<?php
/**
 * Aihcontact
 *
 * PHP version 5
 *
 * @category Model
 * @package  Croogo
 * @version  1.0
 * @author   Tran Van Dung <dungtv@ic-t.info>
 * @license  http://www.opensource.org/licenses/mit-license.php The MIT License
 * @link     http://www.croogo.org
 */
class Aihcontact extends AppModel {
/**
 * Model name
 *
 * @var string
 * @access public
 */
    public $name = 'Aihcontact';
/**
 * Behaviors used by the Model
 *
 * @var array
 * @access public
 */
    public $actsAs = array(
//        'ExtendAssociations',
        'Encoder',
        'Cached' => array(
            'prefix' => array(
                'aihcontact_',
            ),
        ),
    );
/**
 * Validation
 *
 * @var array
 * @access public
 */
    public $validate = array(
        'name' => array(
            'rule' => 'notEmpty',
            'message' => 'This field cannot be left blank.',
        ),
        'address' => array(
            'rule' => 'notEmpty',
            'message' => 'This field cannot be left blank.',
        ),
    );
/**
 * Model associations: belongsTo
 *
 * @var array
 * @access public
 */
    public $belongsTo = array(
        'Contacttype' => array(
            'className' => 'Contacttype',
            'foreignKey' => 'contacttype_id',
            'conditions' => '',
            'fields' => '',
            'order' => '',
        ),
    );
/**
 * Model associations: hasAndBelongsToMany
 *
 * @var array
 * @access public
 */
//    public $hasAndBelongsToMany = array(
//        'Bank' => array(
//            'className' => 'Bank',
//            'with' => 'AihcontactsBank',
//            'joinTable' => 'aihcontacts_banks',
//            'foreignKey' => 'aihcontact_id',
//            'associationForeignKey' => 'bank_id',
//            'unique' => true,
//            'conditions' => '',
//            'fields' => '',
//            'order' => '',
//            'limit' => '',
//            'offset' => '',
//            'finderQuery' => '',
//            'deleteQuery' => '',
//            'insertQuery' => '',
//        ),
//    );
    public function lock($ids=array(), $tbl='cc_banks', $lock=1) { // $tbl='cc_contacttypes'
        if($ids != null) {
            return $this->query("UPDATE `".$tbl."` AS `TBL` SET `TBL`.`lock`=`TBL`.`lock`+".$lock." WHERE `TBL`.`id` IN (".  implode(',', $ids).") ");
        }
        return false;
    }
}
?>